<?php
	include("../include/config.php");
	include("../include/functions.php");
	$_POST['created_date'] = date("Y-m-d H:i:s");
	$_POST['updated_date'] = date("Y-m-d H:i:s");
	if($_GET['table']){		mysqli_query($db_connect, "DELETE FROM `cns_gallery` WHERE id = '$_GET[id]'");
		//deleterow($_GET['table'],array('id'=>$_GET['id']));
		header("location:../admin.php?data=gallary&msg=delete");
	}else{
		foreach($_FILES as $userfile)
		{
			 // store the file information to variables for easier access
			for($i=0;$i<count($userfile['name']);$i++)
			{
				$tmp_name = $userfile['tmp_name'][$i];
				$type = $userfile['type'];
				$name = $userfile['name'][$i];
				$size = $userfile['size'];
$img=rand().$name;
				$imagespath="../../gallary_images/".$img;
				copy($tmp_name,$imagespath);
				$_POST['image']=$img;				mysqli_query($db_connect, "INSERT INTO `cns_gallery`(`title`, `image`, `created_date`, `updated_date`)				VALUES ('$_POST[title]','$_POST[image]','$_POST[created_date]','$_POST[updated_date]')");
			  // db_insert(DB_PREFIX.'gallery',$_POST);
			}
		}
		
				
		
		header("location:../admin.php?data=gallary&msg=success");
	}
?>